/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.d2g.openrealestate.persistence;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author d2g
 */
@Entity
@Table(name = "property", catalog = "dd111", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Property.findAll", query = "SELECT p FROM Property p"),
    @NamedQuery(name = "Property.findByIdProperty", query = "SELECT p FROM Property p WHERE p.idProperty = :idProperty"),
    @NamedQuery(name = "Property.findByAddress", query = "SELECT p FROM Property p WHERE p.address = :address"),
    @NamedQuery(name = "Property.findByAddress2", query = "SELECT p FROM Property p WHERE p.address2 = :address2"),
    @NamedQuery(name = "Property.findByPostcode", query = "SELECT p FROM Property p WHERE p.postcode = :postcode"),
    @NamedQuery(name = "Property.findByNumberBedroom", query = "SELECT p FROM Property p WHERE p.numberBedroom = :numberBedroom"),
    @NamedQuery(name = "Property.findByNumberBathroom", query = "SELECT p FROM Property p WHERE p.numberBathroom = :numberBathroom"),
    @NamedQuery(name = "Property.findByGarden", query = "SELECT p FROM Property p WHERE p.garden = :garden"),
    @NamedQuery(name = "Property.findByFurniture", query = "SELECT p FROM Property p WHERE p.furniture = :furniture"),
    @NamedQuery(name = "Property.findBySizeSquareMetre", query = "SELECT p FROM Property p WHERE p.sizeSquareMetre = :sizeSquareMetre"),
    @NamedQuery(name = "Property.findByDescription", query = "SELECT p FROM Property p WHERE p.description = :description")})
public class Property implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id_property", nullable = false)
    private Long idProperty;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 200)
    @Column(name = "address", nullable = false, length = 200)
    private String address;
    @Size(max = 200)
    @Column(name = "address2", length = 200)
    private String address2;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 15)
    @Column(name = "postcode", nullable = false, length = 15)
    private String postcode;
    @Column(name = "number_bedroom")
    private Integer numberBedroom;
    @Column(name = "number_bathroom")
    private Integer numberBathroom;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "garden", nullable = false, length = 45)
    private String garden;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "furniture", nullable = false, length = 45)
    private String furniture;
    @Basic(optional = false)
    @NotNull
    @Column(name = "size_square_metre", nullable = false)
    private int sizeSquareMetre;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10000)
    @Column(name = "description", nullable = false, length = 10000)
    private String description;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idProperty")
    private Collection<Announce> announceCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idProperty")
    private Collection<Image> imageCollection;
    @JoinColumn(name = "owner_username", referencedColumnName = "username", nullable = false)
    @ManyToOne(optional = false)
    private Owner ownerUsername;
    @JoinColumn(name = "agent_username", referencedColumnName = "username")
    @ManyToOne
    private Agent agentUsername;

    public Property() {
    }

    public Property(Long idProperty) {
        this.idProperty = idProperty;
    }

    public Property(Long idProperty, String address, String postcode, String garden, String furniture, int sizeSquareMetre, String description) {
        this.idProperty = idProperty;
        this.address = address;
        this.postcode = postcode;
        this.garden = garden;
        this.furniture = furniture;
        this.sizeSquareMetre = sizeSquareMetre;
        this.description = description;
    }

    public Long getIdProperty() {
        return idProperty;
    }

    public void setIdProperty(Long idProperty) {
        this.idProperty = idProperty;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAddress2() {
        return address2;
    }

    public void setAddress2(String address2) {
        this.address2 = address2;
    }

    public String getPostcode() {
        return postcode;
    }

    public void setPostcode(String postcode) {
        this.postcode = postcode;
    }

    public Integer getNumberBedroom() {
        return numberBedroom;
    }

    public void setNumberBedroom(Integer numberBedroom) {
        this.numberBedroom = numberBedroom;
    }

    public Integer getNumberBathroom() {
        return numberBathroom;
    }

    public void setNumberBathroom(Integer numberBathroom) {
        this.numberBathroom = numberBathroom;
    }

    public String getGarden() {
        return garden;
    }

    public void setGarden(String garden) {
        this.garden = garden;
    }

    public String getFurniture() {
        return furniture;
    }

    public void setFurniture(String furniture) {
        this.furniture = furniture;
    }

    public int getSizeSquareMetre() {
        return sizeSquareMetre;
    }

    public void setSizeSquareMetre(int sizeSquareMetre) {
        this.sizeSquareMetre = sizeSquareMetre;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @XmlTransient
    public Collection<Announce> getAnnounceCollection() {
        return announceCollection;
    }

    public void setAnnounceCollection(Collection<Announce> announceCollection) {
        this.announceCollection = announceCollection;
    }

    @XmlTransient
    public Collection<Image> getImageCollection() {
        return imageCollection;
    }

    public void setImageCollection(Collection<Image> imageCollection) {
        this.imageCollection = imageCollection;
    }

    public Owner getOwnerUsername() {
        return ownerUsername;
    }

    public void setOwnerUsername(Owner ownerUsername) {
        this.ownerUsername = ownerUsername;
    }

    public Agent getAgentUsername() {
        return agentUsername;
    }

    public void setAgentUsername(Agent agentUsername) {
        this.agentUsername = agentUsername;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idProperty != null ? idProperty.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Property)) {
            return false;
        }
        Property other = (Property) object;
        if ((this.idProperty == null && other.idProperty != null) || (this.idProperty != null && !this.idProperty.equals(other.idProperty))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.d2g.openrealestate.persistence.Property[ idProperty=" + idProperty + " ]";
    }
    
}
